package com.example.mychatroom.serviceImpl;

import com.example.mychatroom.mapper.MessageMapper;
import com.example.mychatroom.model.Message;
import com.example.mychatroom.serviceApi.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @className: MessageServiceImpl
 * @author: 十三
 * @description:
 * @date: 2025/3/18 17:01
 */
@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public List<Message> getMessageBySessionId(Integer sessionId) {
        List<Message> messages = messageMapper.getMessagesBySessionId(sessionId);
        //针对查询结果，进行逆置操作，毕竟界面上需要的是按照时间升序排列的消息，此处得到的是按照时间降序排列的消息
        Collections.reverse(messages);
        return messages;
    }
}
